﻿using ComponentFactory.Krypton.Toolkit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;

namespace EasyERP_CL
{
    /// <summary>
    /// 自定义TextBox控件，添加垃圾桶图标按钮，实现点击垃圾桶图标按钮清除空间输入内容
    /// </summary>
    public class EasyERP_TextBox : KryptonTextBox
    {
        /// <summary>
        /// 声明垃圾桶图标按钮对象
        /// </summary>
        private readonly ButtonSpecAny BtnClear = new ButtonSpecAny();

        /// <summary>
        /// 构造函数
        /// </summary>
        public EasyERP_TextBox()
        {
            //添加点击事件
            BtnClear.Click += new EventHandler(BtnClear_Click);

            //为按钮添加垃圾桶图标
            BtnClear.Image = Properties.Resources.edit_clear;
            BtnClear.Style = PaletteButtonStyle.ListItem;
            BtnClear.Type = PaletteButtonSpecStyle.Close;

            //TextBox锚点位置
            Anchor = AnchorStyles.Left;
            //向TextBox里面添加Button
            ButtonSpecs.AddRange(new ButtonSpecAny[] { BtnClear });
            //TextBox边框的颜色
            StateCommon.Border.Color1 = Color.Gray;
            StateCommon.Border.Color2 = Color.Gray;
            //TextBox边框
            StateCommon.Border.DrawBorders = PaletteDrawBorders.Top | PaletteDrawBorders.Bottom
                | PaletteDrawBorders.Left
                | PaletteDrawBorders.Right;
            //TextBoxPadding
            StateCommon.Content.Padding = new Padding(4);
        }

        /// <summary>
        /// 单击垃圾桶图标事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnClear_Click(object sender, EventArgs e)
        {
            //清除TextBox的内容
            Clear();
            //获取焦点
            Focus();
        }
    }
}
